import random

import allure

from base.base_page import BasePage
from locator.home_page_loc import *


class HomePage(BasePage):
    @allure.step("点击首页搜索按钮")
    def search_book(self, txt):
        self.locator_element_with_wait(search_box_loc).send_keys(txt)
        self.locator_element_with_wait(search_btn_loc).click()

    @allure.step("点击首页登录按钮")
    def login_entrance(self):
        self.locator_element_with_wait(login_btn_loc).click()

    @allure.step("点击首页注册按钮")
    def register_entrance(self):
        self.locator_element_with_wait(register_btn_loc).click()

    @allure.step("点击我的书架按钮")
    def click_bookshelf_btn(self):
        self.locator_element_with_wait(bookshelf_btn_loc).click()

    # @allure.step("获取热门文章中书籍名称")
    # def get_hot_articles_book_names(self):
    #     elements = self.locator_elements_with_wait(hot_articles_loc)
    #     random.choice(elements).click()

    @allure.step("随机点击一本热门文章中书籍")
    def get_hot_books_name(self):
        elements = self.locator_elements_with_wait(hot_articles_loc)
        element = random.choice(elements)
        book_name = element.text
        element.click()
        return book_name

    @allure.step("随机点击一本热门推荐和竞品推荐部分的书籍")
    def get_boutique_book(self):
        elements = self.locator_elements_with_wait(book_info_loc)
        element = random.choice(elements)
        book_name = element.text
        element.click()
        return book_name

    @allure.step("随机点击一本本周强推，点击榜单，新书榜单，最新更新，更新榜单中的书籍")
    def get_other_book_name(self):
        elements = self.locator_elements_with_wait(all_book_name_loc)
        element = random.choice(elements)
        book_name = element.text
        element.click()
        return book_name

    @allure.step("点击排行榜")
    def click_chart(self):
        self.locator_element_with_wait(chart_btn_loc).click()

    @allure.step("点击充值")
    def click_recharge_center(self):
        self.locator_element_with_wait(recharge_btn_loc).click()

    @allure.step("点击作家专区")
    def click_author_area(self):
        self.locator_element_with_wait(author_btn_loc).click()
